package mobilesmil.services;

import mobilesmil.activity.R;
import android.app.Activity;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

/**
 * 
 * Singleton class must call {@link #instance()} to access methods.
 *
 */
public class SmilMessages {
	
	public static final String SERVER_HOST = "cscdb.nku.edu";
	public static final String SERVER_USERNAME = "danielsj3";
	public static final String SERVER_PASSWORD = "568csc301";
	public static final String SERVER_SMIL_DIR = "danielsj3/smil";
	public static final String SERVER_PHP_ABSOLUTE_DIR = "http://" + SERVER_HOST + "/csc301/" + SERVER_SMIL_DIR + "/php/";	
	private SmilMessages(){}
	
	/**
	 * Checks to see if the given file is in the unplayed received preferences.
	 * @param calling	The activity that needs to info on the smil file
	 * @param smil		The file name of the smil.
	 * @return 			If the file is in the unplayed received preferences then 
	 * 					the method will return true. If the method returns false 
	 * 					that means the file was not received or it was received and 
	 * 					already played.
	 */
	public static boolean isReceivedAndUnPlayed(Activity calling, String smil){
		smil = smil.replaceAll(".smil", "");
		SharedPreferences pref = calling.getSharedPreferences(calling.getString(R.string.sp_unplayedRecieved), 0);
		return pref.contains(smil);
	}
	
	/**
	 * Sets a newly received smil message in the unplayed received preferences.
	 * @param calling	The Context that needs to info on the smil file
	 * @param smil		The file name of the smil.
	 */
	public static void setReceivedAndUnPlayed(Activity calling, String smil){
		smil = smil.replaceAll(".smil", "");
		SharedPreferences pref = calling.getSharedPreferences(calling.getString(R.string.sp_unplayedRecieved), 0);
		Editor edit = pref.edit();
		edit.putBoolean(smil, false);
		edit.commit();
	}
	
	/**
	 * Sets a received smil message in the unplayed received preferences as played.
	 * This will remove the file from the preferences.
	 * @param calling	The Context that needs to info on the smil file
	 * @param smil		The file name of the smil.
	 */
	public static void setReceivedAndPlayed(Activity calling, String smil){
		smil = smil.replaceAll(".smil", "");
		SharedPreferences pref = calling.getSharedPreferences(calling.getString(R.string.sp_unplayedRecieved), 0);
		Editor edit = pref.edit();
		edit.remove(smil);
		edit.commit();
	} 
}
